/*
 * @Author       : wang chao
 * @Date         : 2023-03-22 07:42:53
 * @LastEditors  : wang chao
 * @LastEditTime : 2023-08-22 15:40:50
 * @FilePath     : lite_mb_utils.h
 * @Description  :
 * Copyright 2023 BingShan, All Rights Reserved.
 */
/*
 * Change Logs:
 * Date           Author       Notes
 * 2020-08-21     chenbin      small mb the first version
 */
#ifndef _LITE_MB_UTILS_H_
#define _LITE_MB_UTILS_H_

#include "stdint.h"
#include "stdio.h"
#include "string.h"

/**
 * UTILS FUNCTIONS
 **/
uint16_t mb_crc16(uint8_t* buffer, uint16_t buffer_length);
int      mb_check_addr_num(uint8_t function, uint16_t address, uint16_t num);
void     mb_byte_copy(uint8_t* des, uint8_t* src, int num);
void     mb_coil_h2m(uint8_t* des, uint8_t* src, int coil_num);
void     mb_coil_m2h(uint8_t* des, uint8_t* src, int coil_num);
void     mb_reg_h2m(void* dest_mb_reg, void* source_host, int reg_num);
void     mb_reg_m2h(void* dest_host, void* source_mb_reg, int reg_num);

int      lite_dio_get_val(uint8_t* array, uint16_t index);
void     lite_dio_set_val(uint8_t* array, uint16_t index, uint16_t status);
uint16_t lite_aio_get_val(uint16_t* array, uint16_t index);
void     lite_aio_set_val(uint16_t* array, uint16_t index, uint16_t status);

#endif /* _LITE_MODBUS_BASE_H_ */
